package com.burstly.lib.component.networkcomponent.burstly;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import com.burstly.lib.component.ComponentState;
import com.burstly.lib.component.IAdaptorController;
import com.burstly.lib.component.IBurstlyAdaptorListener.FullscreenInfo;
import com.burstly.lib.component.IInternalBurstlyAdListener;
import com.burstly.lib.component.ITrackClickResponseHandler;
import com.burstly.lib.component.networkcomponent.burstly.html.ScriptInterstitialOverlay;
import com.burstly.lib.component.networkcomponent.burstly.html.rewards.RewardsFullscreenOverlay;
import com.burstly.lib.component.networkcomponent.burstly.html.rewards.RewardsView;
import com.burstly.lib.component.networkcomponent.burstly.video.BurstlyVideoAdaptor;
import com.burstly.lib.network.beans.DestinationType;
import com.burstly.lib.network.beans.ResponseBean.ResponseData;
import com.burstly.lib.network.beans.TrackClickResult;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.UiSafeWebView;
import com.burstly.lib.util.Utils;
import java.lang.ref.Reference;

public class ClickResponseHandler
  implements ITrackClickResponseHandler, OverlayContainer.IOverlayListener
{
  protected static final LoggerExt LOG = LoggerExt.getInstance();
  private static final String TAG = ClickResponseHandler.class.getSimpleName();
  protected final Context mContext;
  protected IAdaptorController mController;
  protected final ComponentState mCurrentState;

  public ClickResponseHandler(Context paramContext, ComponentState paramComponentState)
  {
    this.mContext = paramContext;
    this.mCurrentState = paramComponentState;
  }

  private FullscreenParams createVideoParametersObject()
  {
    FullscreenParams localFullscreenParams = new FullscreenParams();
    FullscreenParams.VideoParams localVideoParams = localFullscreenParams.getVideoParams();
    localVideoParams.setShowVisitButton(false);
    localVideoParams.setShowSkipButtonAfter(Integer.valueOf(0));
    localVideoParams.setMiddleVideoCallback(this.mCurrentState.getResponseData().getValidCbmArray());
    localVideoParams.setEndVideoCallback(this.mCurrentState.getResponseData().getValidCbeArray());
    return localFullscreenParams;
  }

  private DestinationType getDestType(TrackClickResult paramTrackClickResult)
  {
    Integer localInteger = paramTrackClickResult.getDestType();
    if (localInteger != null);
    while (true)
    {
      return Utils.getDestinationByCode(localInteger);
      localInteger = this.mCurrentState.getResponseData().getDestType();
    }
  }

  private String getUrl(TrackClickResult paramTrackClickResult)
  {
    String str1 = paramTrackClickResult.getLocation();
    String str2 = getOverridenLocationUrl();
    if (str1 != null)
      return str1.trim();
    if (str2 != null)
      return str2.trim();
    return null;
  }

  private void launchDefaultActivity(String paramString)
    throws ActivityNotFoundException
  {
    Intent localIntent = new Intent("android.intent.action.VIEW", Uri.parse(paramString));
    this.mContext.startActivity(localIntent);
  }

  private void launchVideoActivity(String paramString)
  {
    if (Utils.isVideoUrl(paramString))
    {
      FullscreenParams localFullscreenParams = createVideoParametersObject();
      BurstlyVideoAdaptor.showActivity(this.mContext, paramString, localFullscreenParams, TAG);
      return;
    }
    LOG.logWarning(TAG, "Can not play video because it does not support this video format.", new Object[0]);
  }

  protected String getOverridenLocationUrl()
  {
    return null;
  }

  public void handleResponse(TrackClickResult paramTrackClickResult, IAdaptorController paramIAdaptorController)
  {
    this.mController = paramIAdaptorController;
    String str = getUrl(paramTrackClickResult);
    LOG.logDebug(TAG, "Url to go by click is :{0}", new Object[] { str });
    if (str == null)
      LOG.logWarning(TAG, "Invalid redirect url: null", new Object[0]);
    while (true)
    {
      return;
      DestinationType localDestinationType = getDestType(paramTrackClickResult);
      switch (1.$SwitchMap$com$burstly$lib$network$beans$DestinationType[localDestinationType.ordinal()])
      {
      default:
      case 1:
      case 2:
      case 3:
      case 4:
      case 5:
      case 6:
      case 7:
      }
      try
      {
        launchDefaultActivity(str);
        i = 1;
        bool = true;
        while (i != 0)
        {
          paramIAdaptorController.getBursltlyAdListener().onShowFullscreen(new IBurstlyAdaptorListener.FullscreenInfo(paramIAdaptorController.getNetworkName(), bool));
          return;
          LOG.logDebug(TAG, "DestType is None. Skipped post click action.", new Object[0]);
          return;
          i = 1;
          bool = true;
          launchVideoActivity(str);
          continue;
          i = 1;
          showScriptInterstitial(str);
          bool = false;
          continue;
          i = 1;
          showRewardsInterstitial(str);
          bool = false;
        }
      }
      catch (ActivityNotFoundException localActivityNotFoundException)
      {
        while (true)
        {
          LOG.logError(TAG, localActivityNotFoundException.getMessage(), new Object[0]);
          boolean bool = false;
          int i = 0;
        }
      }
    }
  }

  public void onCloseOverlay()
  {
    this.mController.getBursltlyAdListener().onHideFullscreen(new IBurstlyAdaptorListener.FullscreenInfo(this.mController.getNetworkName(), false));
  }

  public void onShowOverlay()
  {
    if (BurstlyFullscreenActivity.sActiveActivity != null)
    {
      Activity localActivity = (Activity)BurstlyFullscreenActivity.sActiveActivity.get();
      if (localActivity != null)
        localActivity.finish();
    }
  }

  protected void showRewardsInterstitial(String paramString)
  {
    RewardsView localRewardsView = new RewardsView(this.mContext);
    RewardsFullscreenOverlay localRewardsFullscreenOverlay = new RewardsFullscreenOverlay(localRewardsView);
    Integer localInteger = this.mCurrentState.getResponseData().getSkipButtonActivationTime();
    if (localInteger != null)
      localRewardsFullscreenOverlay.setCloseButtonActivationTimeout(1000 * localInteger.intValue());
    localRewardsView.loadUrl(paramString);
    localRewardsFullscreenOverlay.setOverlayListener(this);
    localRewardsFullscreenOverlay.showOverlayed();
  }

  protected void showScriptInterstitial(String paramString)
  {
    UiSafeWebView localUiSafeWebView = new UiSafeWebView(this.mContext);
    ScriptInterstitialOverlay localScriptInterstitialOverlay = new ScriptInterstitialOverlay(localUiSafeWebView);
    Integer localInteger = this.mCurrentState.getResponseData().getSkipButtonActivationTime();
    if (localInteger != null)
      localScriptInterstitialOverlay.setCloseButtonActivationTimeout(1000 * localInteger.intValue());
    localScriptInterstitialOverlay.setOverlayListener(this);
    localUiSafeWebView.loadUrl(paramString);
    localScriptInterstitialOverlay.showOverlayed();
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.ClickResponseHandler
 * JD-Core Version:    0.6.2
 */